using NUnit.Framework;

namespace ValidationFramework.Tests
{
    public static class AttributeTester
    {

		public static void CheckDefaultValues<T>(RuleAttribute ruleAttribute, bool checkProperty, bool checkParameter)
		{
			Assert.IsNull(ruleAttribute.ErrorMessage);
			Assert.IsNull(ruleAttribute.RuleSet);
			Assert.IsFalse(ruleAttribute.UseErrorMessageProvider);
			if (checkProperty)
			{
				var propertyRule = TypeHelper.CreatePropertyRule<Rule>(ruleAttribute, new MockPropertyDescriptor<T>("foo"));
				Assert.IsNull(propertyRule.ErrorMessage);
				Assert.IsFalse(propertyRule.UseErrorMessageProvider);
			}
			if (checkParameter)
			{
				var parameterRule = TypeHelper.CreateParameterRule<Rule>(ruleAttribute, new MockParameterDescriptor<T>("foo"));
				Assert.IsNull(parameterRule.ErrorMessage);
				Assert.IsFalse(parameterRule.UseErrorMessageProvider);
			}
		}

    	public static void CheckNonDefaultValues<T>(RuleAttribute ruleAttribute, bool checkProperty, bool checkParameter)
        {
            const string expectedRuleSet = "MYRULESET";
            const string expectedErrorMessage = "ErrorMessage";

            ruleAttribute.UseErrorMessageProvider = true;
            ruleAttribute.RuleSet = expectedRuleSet;
            ruleAttribute.ErrorMessage = expectedErrorMessage;

           
           Assert.AreEqual(expectedErrorMessage, ruleAttribute.ErrorMessage);
            Assert.IsTrue(ruleAttribute.UseErrorMessageProvider);
            Assert.AreEqual(expectedRuleSet, ruleAttribute.RuleSet);
			if (checkProperty)
			{
				var propertyRule = TypeHelper.CreatePropertyRule<Rule>(ruleAttribute, new MockPropertyDescriptor<T>("foo"));
				Assert.AreEqual(expectedErrorMessage, propertyRule.ErrorMessage);
				Assert.IsTrue(propertyRule.UseErrorMessageProvider);
			}
    		if (checkParameter)
    		{
    			var parameterRule = TypeHelper.CreateParameterRule<Rule>(ruleAttribute, new MockParameterDescriptor<T>("foo"));
    			Assert.AreEqual(expectedErrorMessage, parameterRule.ErrorMessage);
    			Assert.IsTrue(parameterRule.UseErrorMessageProvider);
    		}
        }
    }
}
